// 引入axios组件
import axios from "axios";
import qs from "qs"; //处理数据  qs.stringify(params)
import { checkRule } from "@/assets/js/public"; //引入公共js文件
export default {
  data() {
    return {
      defaultList: [
        {
          name: "a42bdcc1178e62b4694c830f028db5c0",
          url: "http://img.guanchao.site/sowing/5ba9cee56b70c.jpeg",
        },
        {
          name: "bc7521e033abdd1e92222d733590f104",
          url: "http://img.guanchao.site/sowing/5ba9cf2fcc1fd.jpeg",
        },
      ],
      imgName: "",
      visible: false,
    };
  },
  created() {
    this.$Spin.show();
    setTimeout(() => {
      this.$Spin.hide();
    }, 500);
  },
  computed: {
    uploadList() {
      return this.$store.state.bak.sowingList.sowingList;
    },
  },
  methods: {
    // 看大图
    handleView(item) {
      this.imgName = item.imgpath;
      this.visible = true;
    },
    // 删除图片
    handleRemove(file) {
      console.log(file);
      const self = this;
      axios({
        method: "post",
        url: "/admin/website/delSowing",
        data: { id: file.id },
      })
        .then(function(response) {
          checkRule(response, self); //检查是否有权限

          if (response.data.code == 1) {
            for (let value in self.uploadList) {
              if (self.uploadList[value].id == file.id) {
                self.uploadList.splice(value, 1); //如果把那个1改成0，就是不删除
              }
            }
            self.$Message.success("操作成功"); //报错
          } else {
            self.$Message.error("操作失败"); //报错
          }
        })
        .catch(function(response) {
          self.$Message.error("请求失败"); //报错
        }); //*/
    },
    // 成功回调
    handleSuccess(res, file) {
      console.log(res);
      console.log(file);
      this.uploadList.push(res);
    },
    handleFormatError(file) {
      this.$Notice.warning({
        title: "文件格式警告",
        desc: " 我们只允许上传 jpg,jpeg,png,gif ",
      });
    },
    handleMaxSize(file) {
      this.$Notice.warning({
        title: "文件大小警告",
        desc: file.name + "超过了2M",
      });
    },
    handleBeforeUpload() {
      const check = this.uploadList.length < 5;
      if (!check) {
        this.$Notice.warning({
          title: "最多只能上传5张图片",
        });
      }
      return check;
    }, //*/
  },
};
